package Preferences;

import java.util.ArrayList;

import javax.annotation.PostConstruct;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

import bean.general.Style;

import com.myLogger.LoggerManager;

import dao.DaoException;
import dao.DaoStyle;
import dao.NotFoundException;

@ManagedBean
@ApplicationScoped
public class GestioneStili {
	@ManagedProperty(value="#{log.logger}")
	private LoggerManager log;
	public void setLog(LoggerManager log) {
		this.log = log;
	}

	@ManagedProperty(value="#{daoStyle}")
	private DaoStyle daoStyle;
	public void setDaoStyle(DaoStyle daoStyle) {
		this.daoStyle = daoStyle;
	}
	
	private ArrayList<Style> stili;
	
	@PostConstruct
	public void init(){
		try {
			stili = daoStyle.getStyles();
		} catch (DaoException e) {
			log.logError(e);
			//TODO
			//gestire l'errore
		} catch (NotFoundException e) {
			stili = new ArrayList<Style>(); 
			//			log.logError(e);
			//TODO
			//gestire l'errore
		}
		for (Style s : stili)
			System.out.println(s);
	}
	
	public boolean isNotEmpty(){
		return stili.size() > 0;
	}

	public boolean isEmpty(){
		return stili.size() == 0;
	}

	////////////////////////////////////////////////////////////////////
	//Getters and setters
	public ArrayList<Style> getStili() {
		return stili;
	}
	public void setStili(ArrayList<Style> stili) {
		this.stili = stili;
	}
	////////////////////////////////////////////////////////////////////
}
